﻿using log4net;
using log4net.Config;
using System;
using System.IO;

namespace MvcApplication.Common
{
    public static class LogUtil
    {
        static ILog _errorLogger = LogManager.GetLogger("Error");

        public static void Error(string message)
        {
            _errorLogger.Error(message);
        }

        public static void Error(string message, Exception ex)
        {
            _errorLogger.Error(message, ex);
        }

        public static void Info(string message)
        {
            _errorLogger.Info(message);
        }

        public static void Info(string message, Exception ex)
        {
            _errorLogger.Info(message, ex);
        }

        /// <summary>
        /// 自定义的文件日志系统
        /// </summary>
        /// <param name="logMessage"></param>
        //public static void Debug(string logMessage)
        //{
        //    var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory
        //        , "LogDebug");
        //    if (!Directory.Exists(path)) Directory.CreateDirectory(path);

        //    var filePath = Path.Combine(path
        //        , string.Format("{0}.log", DateTime.Now.ToString("yyyy-MM-dd")));
        //    if (!File.Exists(filePath)) using (File.Create(filePath)) ;

        //    File.AppendAllText(filePath, string.Format("[时间:] {0}\r\n[日志:] {1}\r\n"
        //        , DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
        //        , logMessage));
        //}

    }
}
